package com.exchange.utils.result;

import java.util.Arrays;

/***
 *                    .::::.
 *                  .::::::::.
 *                 ::::::::::: 
 *             ..:::::::::::' 
 *           '::::::::::::'
 *             .::::::::::
 *        '::::::::::::::..
 *             ..::::::::::::.
 *           ``::::::::::::::::
 *            ::::``:::::::::'        .:::.
 *           ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *        .:::'       :::::  .:::::::::' ':::::.
 *       .::'        :::::.:::::::::'      ':::::.
 *      .::'         ::::::::::::::'         ``::::.
 *  ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 *                    '.:::::'                    ':'````..
 *
 * @Author liuhai
 * @Date 2020-10-04 11:39:01
 * @Description 返回结果代码枚举
 */
public enum ResultCodeEnum {
    // 成功
    SUCCESS("1000"),
    // 失败
    FAIL("1001"),
    // 报错/异常
    ERROR("1002"),
    // 未登陆
    NOLOGIN("1003");

    private String code;

    ResultCodeEnum(String code){
        this.code = code;
    }

    public String getCode(){
        return code;
    }

    /**
     * 校验编码是否存在
     * @param code
     * @return
     */
    public static boolean exist(String code){
        ResultCodeEnum[] values = ResultCodeEnum.values();
        return Arrays.stream(values).anyMatch(status -> status.getCode() == code);
    }
}
